package com.wwy.arithmetic.suanfa;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 获取excel中列表
 */
public class ExcelNumber {

    public static void main(String[] args) {
        List<Character> letters = IntStream.rangeClosed('A', 'Z')
                .mapToObj(c -> (char) c)
                .collect(Collectors.toList());
        String name = judge(1);
        String name1 = judgeString(letters, 2147483647);
        System.out.println(name1);
    }

    static String judge(int columnNumber) {
        StringBuffer sb = new StringBuffer();
        while (columnNumber > 0) {
            int a0 = (columnNumber - 1) % 26 + 1;
            sb.append((char) (a0 - 1 + 'A'));
            columnNumber = (columnNumber - a0) / 26;
        }
        return sb.reverse().toString();

    }

    static String judgeString(List<Character> list, int columnNumber) {
        StringBuilder name = new StringBuilder();
        if (columnNumber <= 26) {
            name.append(list.get(columnNumber - 1));
            return name.toString();
        }
        while (columnNumber > 0) {
            int a = (columnNumber-1 )% 26 +1;
            name.append(list.get(a - 1));
            columnNumber = (columnNumber - a) / 26;
        }
        return name.reverse().toString();
    }

}
